package com.yanqu.road.entity.forbiddenword;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.Set;

@FieldTypeAnnotation(tableName = "t_s_forbidden_word_overseas")
public class ForbiddenWordOverSeasData extends DataObject {
    @FieldTypeAnnotation(desc = "id", isIndex = true, select = true, update = true)
    private int id;
    @FieldTypeAnnotation(desc = "屏蔽词")
    private Set<String> wordSet = new ConcurrentHashSet<>();

    public ForbiddenWordOverSeasData() {
    }

    public ForbiddenWordOverSeasData(int id) {
        this.id = id;
        setInsertOption();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Set<String> getWordSet() {
        return wordSet;
    }

    public void setWordSet(Set<String> wordSet) {
        this.wordSet = wordSet;
    }

    public boolean contains(String word) {
        return wordSet.contains(word);
    }

    public boolean isFull(int oneLineWordNum) {
        return wordSet.size() >= oneLineWordNum;
    }

    public void addWord(String word) {
        wordSet.add(word);
        setUpdateOption();
    }

    public boolean removeWord(String word) {
        if (wordSet.remove(word)) {
            setUpdateOption();
            return true;
        }
        return false;
    }
}
